package com.ruyuan.user.server.util;

import com.ruyuan.user.server.domain.model.Organization;
import org.apache.commons.collections.CollectionUtils;

import java.util.Map;

/**
 * @author xx
 */
public class OrganizationUtil {

    public static String buildOrgPathDisplayText(Organization organization, Map<Long, Organization> orgMap) {
        if (organization == null) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        if (CollectionUtils.isNotEmpty(organization.getOrgPath())) {
            organization.getOrgPath().stream().filter(orgMap::containsKey).map(orgMap::get)
                    .forEach(orgPath -> sb.append(orgPath.getName()).append(">"));
        }
        sb.append(organization.getName());
        return sb.toString();
    }

}
